<template>
  <div class="bg-[#232324] h-[100%]">
    <el-collapse v-loading="loading" v-model="activeNames">
      <el-form label-width="100" :model="states" size="default">
        <el-collapse-item
          :title="`缩放区域${i + 1}`"
          :name="i + 1 + 'dataZoom'"
          v-for="(item, i) in dataZoom"
          :key="i + 'dataZoom'"
        >
          <el-form-item label="是否显示">
            <el-switch v-model="item.show" />
          </el-form-item>
          <el-form-item label="是否显示阴影">
            <el-switch v-model="item.showDataShadow" />
          </el-form-item>

          <el-form-item label="背景颜色">
            <el-color-picker v-model="item.backgroundColor" />
          </el-form-item>
          <el-form-item label="选中范围颜色">
            <el-color-picker v-model="item.fillerColor" />
          </el-form-item>
          <el-form-item label="边框颜色">
            <el-color-picker v-model="item.borderColor" />
          </el-form-item>
          <el-form-item label="阴影线条颜色">
            <el-color-picker v-model="item.dataBackground.lineStyle.color" />
          </el-form-item>
          <el-form-item label="阴影填充颜色">
            <el-color-picker v-model="item.dataBackground.areaStyle.color" />
          </el-form-item>
          <el-form-item label="两侧缩放颜色">
            <el-color-picker v-model="item.handleStyle.color" />
          </el-form-item>
          <el-form-item label="移动手柄颜色">
            <el-color-picker v-model="item.moveHandleStyle.color" />
          </el-form-item>

          <el-form-item label="数据起始数" v-if="i == 0">
            <el-input-number v-model="item.start" />
          </el-form-item>
          <el-form-item label="数据结束数" v-if="i == 0">
            <el-input-number v-model="item.end" />
          </el-form-item>

          <el-form-item label="组件的宽度" v-if="i == 1">
            <el-input v-model="item.width" />
          </el-form-item>
          <el-form-item label="组件的高度" v-if="i == 1">
            <el-input v-model="item.height" />
          </el-form-item>

          <el-form-item label="距离左侧距离">
            <el-input v-model="item.left" />
          </el-form-item>
          <el-form-item label="距离上侧距离">
            <el-input v-model="item.top" />
          </el-form-item>
          <el-form-item label="距离右侧距离">
            <el-input v-model="item.right" />
          </el-form-item>
          <el-form-item label="距离下侧距离">
            <el-input v-model="item.bottom" />
          </el-form-item>
        </el-collapse-item>
        <el-collapse-item
          :title="`柱状-${i + 1}`"
          :name="i + 1"
          v-for="(item, i) in states"
          :key="item.name + i + 'a'"
        >
          <el-form-item label="柱宽度">
            <el-input v-model="item.barWidth" />
          </el-form-item>
          <el-form-item label="柱颜色">
            <el-color-picker v-model="item.itemStyle.color" />
          </el-form-item>
          <el-form-item label="柱圆角">
            <el-input-number v-model="item.itemStyle.borderRadius" :min="0" />
          </el-form-item>
          <el-form-item label="柱透明度">
            <el-input-number
              v-model="item.itemStyle.opacity"
              :step="0.1"
              :min="0"
              :max="1"
            />
          </el-form-item>
          <el-form-item label="柱背景">
            <el-switch v-model="item.showBackground" />
          </el-form-item>
          <el-form-item label="取消高亮">
            <el-switch v-model="item.emphasis.disabled" />
          </el-form-item>
          <el-form-item label="高亮选项">
            <el-select v-model="item.emphasis.focus" placeholder="Select">
              <el-option label="聚焦系列所有图形" value="series" />
              <el-option label="聚焦当前数据图形" value="self" />
              <el-option label="不淡出其它图形" value="none" />
            </el-select>
          </el-form-item>
          <el-form-item label="柱背景">
            <el-switch v-model="item.showBackground" />
          </el-form-item>
          <el-form-item label="背景色">
            <el-color-picker v-model="item.backgroundStyle.color" />
          </el-form-item>
          <el-form-item label="背景圆角">
            <el-input-number
              v-model="item.backgroundStyle.borderRadius"
              :min="0"
            />
          </el-form-item>
          <el-form-item label="背景透明度">
            <el-input-number
              v-model="item.backgroundStyle.opacity"
              :step="0.1"
              :min="0"
              :max="1"
            />
          </el-form-item>
          <el-form-item label="标签文字">
            <el-switch v-model="item.label.show" />
          </el-form-item>
          <el-form-item label="标签文字大小">
            <el-input-number v-model="item.label.fontSize" />
          </el-form-item>
          <el-form-item label="标签文字颜色">
            <el-color-picker v-model="item.label.color" />
          </el-form-item>
          <el-form-item label="标签文字位置">
            <el-select v-model="item.label.position" placeholder="Select">
              <el-option label="top" value="top" />
              <el-option label="left" value="left" />
              <el-option label="right" value="right" />
              <el-option label="bottom" value="bottom" />
            </el-select>
          </el-form-item>
        </el-collapse-item>
      </el-form>
    </el-collapse>
  </div>
</template>

<script setup>
import { watch, onMounted, ref } from "vue";
const loading = ref(true);
const activeNames = ref();
const props = defineProps({
  models: {
    type: Object,
    default: () => ({}),
  },
});
const emit = defineEmits(["update:models", "edit"]);
let states = ref(null);
let dataZoom = ref(null);
onMounted(() => {
  setTimeout(() => {
    loading.value = false;
  }, 200);

  dataZoom.value = JSON.parse(JSON.stringify(props.models.dataZoom));
  states.value = JSON.parse(JSON.stringify(props.models.series));
});

watch(
  () => states.value,
  (val) => {
    emit("update:models", { ...props.models, series: val });
  },
  {
    deep: true,
  }
);
watch(
  () => dataZoom.value,
  (val) => {
    emit("update:models", { ...props.models, dataZoom: val });
  },
  {
    deep: true,
  }
);
</script>

<style scoped lang="scss">
:deep(.el-collapse-item__header) {
  padding-left: 10px !important;
}
:deep(.el-collapse-item__header) {
  padding-left: 10px !important;
}

:deep(.el-input) {
  width: 180px !important;
}
:deep(.el-select) {
  width: 180px !important;
}
</style>
